'''
Created on Apr 16, 2012
TC ID: Ecom_5019
Desc: Kiem thu chuc nang sua thong tin loai tai khoan
@author: lavang
'''
import unittest
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.userTypesFunc import clickOnUserTypes, clickOnNewUserType,\
    createUserType, isUserTypeCreatedSuccessfully, clickOnUserType
from HTMLTestRunner import HTMLTestRunner
import time

username=readData("username")
password=readData("password")
tm_typeName=readData("userTypeName")
tm_type=readData("userType")
tm_typeName2=readData("userTypeName",index=2)
class Ecom_5019(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5019(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
    
        print "Buoc 2: Click vao User Types"
        clickOnUserTypes(self)
        
        print "Buoc 3: Click vao User Type muon sua thong tin"
        clickOnUserType(self,tm_typeName)
        
        print "Buoc 4: Sua ten User type"
        createUserType(self,typeName=tm_typeName2,basicUserType=tm_type,setAll='yes',edit='on')
        
        print "Buoc 5: Xac nhan sua thong tin User Type thanh cong"
        self.assertTrue(isUserTypeCreatedSuccessfully(self,tm_typeName2), "Failed!")
        print "Passed: User Type duoc sua thong tin thanh cong"
    
    def tearDown(self):
        endCondition(self)
        

if __name__ == "__main__":
   #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5019)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin mot User Type'
                    )
    runner.run(suite)